package com.qf.myblogssm.service.serviceImp;

import com.qf.myblogssm.dao.TcommentMapper;
import com.qf.myblogssm.pojo.Tcomment;
import com.qf.myblogssm.service.CommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * create by 王镜 on 2019/6/18 0018 9:10
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    private TcommentMapper tcommentMapper;
    @Override
    public List<Tcomment> getCommentByAid(Integer id) {
        return tcommentMapper.selectByAid(id);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void del(Integer id) {
        tcommentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void add(Tcomment tcomment) {
        //文章的id 内容 昵称
        tcomment.setDiss(0);
        tcomment.setStar(0);
        Date date=new Date();
        tcomment.setTime(date);
        tcommentMapper.insert(tcomment);
    }

    @Override
    public void star(Integer id) {
        tcommentMapper.star(id);
    }

    @Override
    public Tcomment getCommentByid(Integer id) {
        Tcomment tcomment=tcommentMapper.selectByPrimaryKey(id);
        return tcomment;
    }

    @Override
    public void diss(Integer id) {
        tcommentMapper.diss(id);
    }
}
